package com.lqq.designPattern.bulider_pattern.prototype.deepCopy;

import java.io.*;

//Citation测试类
public class CitationTest {
    public static void main(String[] args) throws Exception {
        //原型对象
        Student stu1 = new Student();
        stu1.setName("677");
        Citation citation1 = new Citation();
        citation1.setStu(stu1);

        //序列化反序列进行深克隆
        //序列化对象
        write(citation1);
        //读取对象
        Citation citation2 = read();
        Student stu2 = citation2.getStu();
        stu2.setName("688");

        citation1.show();
        citation2.show();

    }
    //序列化写入磁盘
    public static void write(Citation citation) throws Exception {
        //对象输出流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\Users\\87199\\Desktop\\a.txt"));
        //写对象
        oos.writeObject(citation);
        //关闭流
        oos.close();
    }
    //反序列化读入对象
    public static Citation read() throws Exception {
        //对象输入流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\Users\\87199\\Desktop\\a.txt"));
        //读对象
        Citation citation = (Citation) ois.readObject();
        //返回对象
        return citation;
    }

}
